package com.osi.project.redis.controller.api;

import cn.hutool.core.bean.BeanUtil;
import com.osi.project.config.constants.ProjectConstants;
import com.osi.project.redis.generate.pojo.RedisSlowLogDO;
import com.osi.project.redis.service.RedisService;
import com.osi.start.common.business.dto.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

import com.osi.start.framework.business.service.BaseServiceImpl;
import com.osi.project.redis.manager.RedisSlowLogManager;

import javax.validation.Valid;
import java.util.List;

/**
 * @Desc： 直接供用户端调用的Controller类
 * @author pwh
 * @date 2018年01月01日 09:09:09
 * @Copyright (c) onestop
 */
@Api(tags = "api-Redis相关接口")
@RestController
@RequestMapping(value = ProjectConstants.PATH_BASE + "/api/redis/redisSlowLog")
public class RedisApiController extends BaseServiceImpl {

    @Autowired
    private RedisService redisService;

    @ApiOperation("查询redis最新的10条sql")
    @PostMapping(value = "/querySlowSql")
    public RespVO<BaseListRespDTO<RedisSlowLogDO>> querySlowSql(@RequestBody @Valid BaseRequestDTO req) {
        List<RedisSlowLogDO> redisSlowLogDOList = redisService.queryAndSaveAllSlowSql();
        return RespUtil.success(new BaseListRespDTO<>(redisSlowLogDOList));
    }
}

